package com.controller;

import com.controller.vo.PaymentInfo;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.concurrent.atomic.AtomicInteger;

@RestController
public class PaymentController {

    AtomicInteger atomicInteger = new AtomicInteger(1);

    @RequestMapping("payment")
    public String payment(@RequestBody PaymentInfo paymentInfo){
        if(atomicInteger.getAndIncrement() % 2 !=0){
            return "intending throws exception  when it's not even";
        }

        Assert.isTrue(paymentInfo.getMoney().equals(new BigDecimal(100)) && paymentInfo.getUsername().equals("hcj"),
                " check use info have problem");
        return "success";
    }
}
